package ar.com.cicweb.controllers;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import ar.com.cicweb.dao.CategoriaDAO;
import ar.com.cicweb.dao.MarcaDAO;
import ar.com.cicweb.dao.SubCategoriaDAO;
import ar.com.cicweb.dao.SubMarcaDAO;
import ar.com.cicweb.dominio.Categoria;
import ar.com.cicweb.dominio.Marca;
import ar.com.cicweb.dominio.SubCategoria;
import ar.com.cicweb.dominio.SubMarca;
import ar.com.cicweb.dozer.DozerMapper;


@Controller
public class Carga {
	@Resource(name = "marcaDAO")
	MarcaDAO marcaDAO;

	@Resource(name = "categoriaDAO")
	CategoriaDAO categoriaDAO;

	@Resource(name = "subcategoriaDAO")
	SubCategoriaDAO subcategoriaDAO;

	@Resource(name = "submarcaDAO")
	SubMarcaDAO submarcaDAO;
	
	@Resource(name = "dozerMapper")
	DozerMapper dozerMapper;
	

	
	
	@RequestMapping(value = "doAgregarMarca.htm")
	public void doGuardarMarca(
			@RequestParam String nombre,
			HttpServletRequest req, HttpSession session){
		
		
		Marca mar = new Marca();
		mar.setNombreMarca(nombre);
		
		marcaDAO.guardaMarca(mar);
		
		
		
	}
	
	@RequestMapping(value = "doAgregarSubMarca.htm", method = RequestMethod.POST)
	public @ResponseBody void doGuardarSubMarca(
			@RequestParam String nombre,
			@RequestParam String id,
			HttpServletRequest req,
			HttpSession session){
		
		
		SubMarca m =  new SubMarca();
		m.setNombreSubMarca(nombre);
		m.setSubMarca_idMarca(Integer.parseInt(id));
		
		submarcaDAO.guardaSubMarca(m);
		
		
		
	}
	
	
	@RequestMapping(value = "doAgregarCategoria.htm")
	public void doGuardarCategoria(@RequestParam String nombre,
		
			HttpServletRequest req, HttpSession session){
		
		
		Categoria cat = new Categoria();
		cat.setNombreCategoria(nombre);
		
		categoriaDAO.guardaCategoria(cat);
		
		
		
		
		
	}
	@RequestMapping(value = "doAgregarSubCategoria.htm")
	public void doGuardarSubCategoria(
			@RequestParam String nombre,@RequestParam String id,
			HttpServletRequest req, HttpSession session){
		
		
		SubCategoria sub = new SubCategoria();
		
		sub.setNombreSubCategoria(nombre);
		sub.setIdCategoria(Integer.parseInt(id));
		
		subcategoriaDAO.guardaSubCategoria(sub);
		
		
		
	}
	

}
